package com.appistry.maven.plugin.far;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;

/**
 * Packages the application into a Fabric archive
 * 
 * @goal package
 * @phase package
 * @requiresDependencyResolution runtime
 */
public class FarMojo extends AbstractFarMojo {

	/**
	 * The name of the generated far
	 * 
	 * @parameter expression="${project.build.finalName}"
	 * @required
	 */
	private String farName;

	/**
	 * Type of FabricARchive? ".fabric" or ".far"
	 * 
	 * @parameter default-value="fabric"
	 * @required
	 */
	private String farType;

	public String getFarName() {
		return farName;
	}

	public void setFarName(String farName) {
		this.farName = farName;
	}

	public String getFarType() {
		return farType;
	}

	public void setFarType(String farType) {
		this.farType = farType;
	}

	public void execute() throws MojoExecutionException, MojoFailureException {
		// if src/main/fabric-resources (or specified) directory does not exist,
		// then return
		if (!existsFabricResourcesSourceDirectory()) {
			return;
		}

		getLog().info("In FarMojo");

		performPackage();
	}

	private void performPackage() throws MojoExecutionException {
		getLog().info("Packaging FAR");

		buildFar(getFabricAppDirectory());
	}

}
